class Solution {
    public int minEatingSpeed(int[] piles, int h) {
        int low = 1;
        int higth = 0;//在数组中找到最大值
        for(int pile : piles) {
            higth = Math.max(higth,pile);
        }
        int k = higth;
        while(low < higth) {
            int speed = (higth - low) /2 + low;
            long time = getTime(piles,speed);
            if(time <= h) {
                k = speed;
                higth = speed;
            } else {
                low = speed + 1;
            }
        }
        return k;
    }

    public long getTime(int[] piles,int speed) {
        long time = 0;
        for(int  pile : piles) {
            int a = (pile + speed - 1) / speed;
            time += a;
        }
        return time;
    }
}